home *** CD-ROM | disk | FTP | other *** search
/ PC-SIG Library 8 / PC-SIG Library CD-ROM (8th Edition) (1990-04).iso / 201_300 / disk0202 / tstlpt.c < prev   
Encoding:
C/C++ Source or Header  |  1984-01-01  |  2.1 KB  |  86 lines

  1. /*
  2.  * tstlpt.c  10 Nov 83  Craig Milo Rogers at USC/ISI
  3.  *
  4.  *    This program tests lpt_pkg.c, the line printer port I/O package.
  5.  */
  6.  
  7. #define M_TSTLPT        /* For debugging. */
  8.  
  9. #include "stdio.h"
  10.  
  11. #include "truth.h"
  12. #include "beauty.h"
  13.  
  14. #define BUFLEN 2048        /* LPT1: output buffer length. */
  15. static char lptbuf[BUFLEN];    /* LPT1: output buffer. */
  16.  
  17. static char *pattern = "The quick brown fox jumps over the lazy dog.\r\n";
  18.  
  19. #define UNIT 1            /* Deal only with LPT1: */
  20.  
  21.  
  22. main(argc, argv)
  23. int argc;            /* Number of command arguments. */
  24. char *argv[];            /* Pointers to argument strings. */
  25. {
  26.     char *cp;            /* Output character pointer. */
  27.     int cnt;            /* Output free count. */
  28.     int stat;            /* Printer status. */
  29.     int i;            /* Counters. */
  30.  
  31.     printf("Initializing the interrupt package.\n");
  32.     int_ini();
  33.  
  34.     printf("Partial initialization.\n");
  35.     lpt_ini(UNIT, lptbuf, BUFLEN, FALSE);
  36.  
  37.     printf("Terminating LPT service.\n");
  38.     lpt_trm(UNIT);
  39.  
  40.     printf("Complete initialization.\n");
  41.     lpt_ini(UNIT, lptbuf, BUFLEN, TRUE);
  42.  
  43.     printf("Checking output free count.\n");
  44.     if ((cnt = lpt_ocnt(UNIT)) != BUFLEN) {
  45.     printf("Output free count mismatch: lpt_ocnt() = %d, BUFLEN = %d.\n",
  46.         cnt, BUFLEN);
  47.     }
  48.  
  49.     printf("Getting printer status.\n");
  50.     stat = lpt_stat(UNIT);
  51.     printf("Printer status = %02x.\n", stat);
  52.  
  53.     printf("Printing test message on printer.\n");
  54.     for (i = 0; i < 100; i++) {        /* Print 100 lines: */
  55.     printf(".");            /* One feedback dot per line. */
  56.     for (cp = pattern; *cp; cp++) {
  57.         while (!lpt_putc(UNIT, *cp)) {
  58.         kbhit();
  59.         }
  60.     }
  61.     }
  62.     printf("\n");            /* Terminate the feedback line. */
  63.  
  64.     printf("Waiting for buffer to flush.\n");
  65.     while(lpt_ocnt(UNIT) != BUFLEN) {
  66.     kbhit();
  67.     }
  68.  
  69.     printf("Advance paper and sound alarm.\n");
  70.     lpt_putc(UNIT, 014);
  71.     lpt_putc(UNIT, 007);
  72.  
  73.     printf("Waiting for buffer to flush.\n");
  74.     while(lpt_ocnt(UNIT) != BUFLEN) {
  75.     kbhit();
  76.     }
  77.  
  78.     printf("Terminating LPT service.\n");
  79.     lpt_trm(UNIT);
  80.  
  81.     printf("Terminating interrupt service.\n");
  82.     int_trm();
  83.  
  84.     printf("Done.\n");
  85. }
  86.